package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.xiuxian.config.XiuXianConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.xiuxian.XiuXianMgr;

import java.util.ArrayList;
import java.util.List;

public class XiuXianRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        XiuXianConfig config = XiuXianMgr.getConfig();
        if (config != null && config.getActivityInfo() != null) {
            // 天地灵液
            //addRecycleItemDataEndTime(config.getActivityInfo(), config.getXIUXIAN_ENERGY_RECOVERY_ITEM_ID(), config.getXIUXIAN_XUTIANYUANLING_ITEM_ID());
        }
    }

    private void addRecycleItemDataShowTime(ActivityInfo activityInfo, int itemId, int scoreId) {
        List<String> paramList = new ArrayList<>();
        long recycleTime = activityInfo.getEndShowTime() * 1000L + 600 * 1000;
        paramList.add(String.valueOf(itemId));
        paramList.add(String.valueOf(scoreId));
        paramList.add("0");
        paramList.add(activityInfo.getActivityName());
        ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 1, recycleTime, paramList);
    }

    private void addRecycleItemDataEndTime(ActivityInfo activityInfo, int itemId, int scoreId) {
        List<String> paramList = new ArrayList<>();
        long recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
        paramList.add(String.valueOf(itemId));
        paramList.add(String.valueOf(scoreId));
        paramList.add("1");
        paramList.add(activityInfo.getActivityName());
        ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 1, recycleTime, paramList);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.XiuXian.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if(Integer.parseInt(data.getParamList().get(1)) != 0){
            item2Score(userId, data);
        }else{
            removeItem(userId,data);
        }
    }

    private void removeItem(long userId,ActivityItemRecycleData data){
        int itemId = data.getItemId();
        UserBagItem userBagItem = getUserBagItem(userId, itemId);
        if (userBagItem == null || userBagItem.getNum() <= 0) {
            return;
        }
        removeItem(userBagItem);
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }

}
